<!doctype html>

<html>
<head>
  <link rel="shortcut icon" href="static/images/favicon.ico" type="image/x-icon">
  <title>errorhandlingmechanism.js (Closure Library API Documentation - JavaScript)</title>
  <link rel="stylesheet" href="static/css/base.css">
  <link rel="stylesheet" href="static/css/doc.css">
  <link rel="stylesheet" href="static/css/sidetree.css">
  <link rel="stylesheet" href="static/css/prettify.css">

  <script>
     var _staticFilePath = "static/";
     var _typeTreeName = "goog";
     var _fileTreeName = "Source";
  </script>

  <script src="static/js/doc.js">
  </script>


  <meta charset="utf8">
</head>

<body onload="grokdoc.onLoad();">

<div id="header">
  <div class="g-section g-tpl-50-50 g-split">
    <div class="g-unit g-first">
      <a id="logo" href="index.html">Closure Library API Documentation</a>
    </div>

    <div class="g-unit">
      <div class="g-c">
        <strong>Go to class or file:</strong>
        <input type="text" id="ac">
      </div>
    </div>
  </div>
</div>

<div class="clear"></div>

<h2><a href="closure_goog_storage_mechanism_errorhandlingmechanism.js.html">errorhandlingmechanism.js</a></h2>

<pre class="prettyprint lang-js">
<a name="line1"></a>// Copyright 2012 The Closure Library Authors. All Rights Reserved.
<a name="line2"></a>//
<a name="line3"></a>// Licensed under the Apache License, Version 2.0 (the &quot;License&quot;);
<a name="line4"></a>// you may not use this file except in compliance with the License.
<a name="line5"></a>// You may obtain a copy of the License at
<a name="line6"></a>//
<a name="line7"></a>//      http://www.apache.org/licenses/LICENSE-2.0
<a name="line8"></a>//
<a name="line9"></a>// Unless required by applicable law or agreed to in writing, software
<a name="line10"></a>// distributed under the License is distributed on an &quot;AS-IS&quot; BASIS,
<a name="line11"></a>// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
<a name="line12"></a>// See the License for the specific language governing permissions and
<a name="line13"></a>// limitations under the License.
<a name="line14"></a>
<a name="line15"></a>/**
<a name="line16"></a> * @fileoverview Wraps a storage mechanism with a custom error handler.
<a name="line17"></a> *
<a name="line18"></a> */
<a name="line19"></a>
<a name="line20"></a>goog.provide(&#39;goog.storage.mechanism.ErrorHandlingMechanism&#39;);
<a name="line21"></a>
<a name="line22"></a>goog.require(&#39;goog.storage.mechanism.Mechanism&#39;);
<a name="line23"></a>
<a name="line24"></a>
<a name="line25"></a>
<a name="line26"></a>/**
<a name="line27"></a> * Wraps a storage mechanism with a custom error handler.
<a name="line28"></a> *
<a name="line29"></a> * @param {!goog.storage.mechanism.Mechanism} mechanism Underlying storage
<a name="line30"></a> *     mechanism.
<a name="line31"></a> * @param {goog.storage.mechanism.ErrorHandlingMechanism.ErrorHandler}
<a name="line32"></a> *     errorHandler An error handler.
<a name="line33"></a> * @constructor
<a name="line34"></a> * @extends {goog.storage.mechanism.Mechanism}
<a name="line35"></a> */
<a name="line36"></a>goog.storage.mechanism.ErrorHandlingMechanism = function(mechanism,
<a name="line37"></a>                                                         errorHandler) {
<a name="line38"></a>  goog.base(this);
<a name="line39"></a>
<a name="line40"></a>  /**
<a name="line41"></a>   * The mechanism to be wrapped.
<a name="line42"></a>   * @type {!goog.storage.mechanism.Mechanism}
<a name="line43"></a>   * @private
<a name="line44"></a>   */
<a name="line45"></a>  this.mechanism_ = mechanism;
<a name="line46"></a>
<a name="line47"></a>  /**
<a name="line48"></a>   * The error handler.
<a name="line49"></a>   * @type {goog.storage.mechanism.ErrorHandlingMechanism.ErrorHandler}
<a name="line50"></a>   * @private
<a name="line51"></a>   */
<a name="line52"></a>  this.errorHandler_ = errorHandler;
<a name="line53"></a>};
<a name="line54"></a>goog.inherits(goog.storage.mechanism.ErrorHandlingMechanism,
<a name="line55"></a>              goog.storage.mechanism.Mechanism);
<a name="line56"></a>
<a name="line57"></a>
<a name="line58"></a>/**
<a name="line59"></a> * Valid storage mechanism operations.
<a name="line60"></a> * @enum {string}
<a name="line61"></a> */
<a name="line62"></a>goog.storage.mechanism.ErrorHandlingMechanism.Operation = {
<a name="line63"></a>  SET: &#39;set&#39;,
<a name="line64"></a>  GET: &#39;get&#39;,
<a name="line65"></a>  REMOVE: &#39;remove&#39;
<a name="line66"></a>};
<a name="line67"></a>
<a name="line68"></a>
<a name="line69"></a>/**
<a name="line70"></a> * A function that handles errors raised in goog.storage.  Since some places in
<a name="line71"></a> * the goog.storage codebase throw strings instead of Error objects, we accept
<a name="line72"></a> * these as a valid parameter type.  It supports the following arguments:
<a name="line73"></a> *
<a name="line74"></a> * 1) The raised error (either in Error or string form);
<a name="line75"></a> * 2) The operation name which triggered the error, as defined per the
<a name="line76"></a> *    ErrorHandlingMechanism.Operation enum;
<a name="line77"></a> * 3) The key that is passed to a storage method;
<a name="line78"></a> * 4) An optional value that is passed to a storage method (only used in set
<a name="line79"></a> *    operations).
<a name="line80"></a> *
<a name="line81"></a> * @typedef {function(
<a name="line82"></a> *   (!Error|string),
<a name="line83"></a> *   goog.storage.mechanism.ErrorHandlingMechanism.Operation,
<a name="line84"></a> *   string,
<a name="line85"></a> *   *=)}
<a name="line86"></a> */
<a name="line87"></a>goog.storage.mechanism.ErrorHandlingMechanism.ErrorHandler;
<a name="line88"></a>
<a name="line89"></a>
<a name="line90"></a>/** @override */
<a name="line91"></a>goog.storage.mechanism.ErrorHandlingMechanism.prototype.set = function(key,
<a name="line92"></a>                                                                       value) {
<a name="line93"></a>  try {
<a name="line94"></a>    this.mechanism_.set(key, value);
<a name="line95"></a>  } catch (e) {
<a name="line96"></a>    this.errorHandler_(
<a name="line97"></a>        e,
<a name="line98"></a>        goog.storage.mechanism.ErrorHandlingMechanism.Operation.SET,
<a name="line99"></a>        key,
<a name="line100"></a>        value);
<a name="line101"></a>  }
<a name="line102"></a>};
<a name="line103"></a>
<a name="line104"></a>
<a name="line105"></a>/** @override */
<a name="line106"></a>goog.storage.mechanism.ErrorHandlingMechanism.prototype.get = function(key) {
<a name="line107"></a>  try {
<a name="line108"></a>    return this.mechanism_.get(key);
<a name="line109"></a>  } catch (e) {
<a name="line110"></a>    this.errorHandler_(
<a name="line111"></a>        e,
<a name="line112"></a>        goog.storage.mechanism.ErrorHandlingMechanism.Operation.GET,
<a name="line113"></a>        key);
<a name="line114"></a>  }
<a name="line115"></a>};
<a name="line116"></a>
<a name="line117"></a>
<a name="line118"></a>/** @override */
<a name="line119"></a>goog.storage.mechanism.ErrorHandlingMechanism.prototype.remove = function(key) {
<a name="line120"></a>  try {
<a name="line121"></a>    this.mechanism_.remove(key);
<a name="line122"></a>  } catch (e) {
<a name="line123"></a>    this.errorHandler_(
<a name="line124"></a>        e,
<a name="line125"></a>        goog.storage.mechanism.ErrorHandlingMechanism.Operation.REMOVE,
<a name="line126"></a>        key);
<a name="line127"></a>  }
<a name="line128"></a>};
</pre>


</body>
</html>
